<?php
namespace App\Repositories\Backend;

use App\Models\Comment;
use Illuminate\Support\Facades\Auth;

class CommentRepository extends CommonRepository
{

    public function __construct(Comment $comment)
    {
        parent::__construct($comment);
    }

    /**
     * 列表
     * @param  array $input 查询条件
     * @return object
     */
    public function getLists($input)
    {
        $default_search = [
            'filter' => ['id','like_number', 'user_image', 'user_name', 'model','content', 'model_id', 'created_at'],
            'sort'   => [
                'created_at' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->parseWheres($search)->with('doctor')->paginate();
    }


    /**
     * 新增
     * @param  string   $user_name    评论用户名字
     * @param  string   $user_image   评论用户照片路径
     * @param  int      $like_number  点赞数量
     * @param  string   $content      内容
     * @return object
     */
    public function create($user_name, $user_image, $like_number, $content, $model_id)
    {
        $result = $this->model->create([
            'user_name' => $user_name,
            'user_image'      => $user_image,
            'like_number' => $like_number,
            'content'            => $content,
            'model_id'            => $model_id,
        ]);

        return $result;
    }

    public function destroy($id)
    {
        return $this->deleteById($id);
    }


    public function getList($input)
    {
        $default_search = [
            'filter' => ['id','like_number', 'user_image', 'user_name', 'model','content', 'model_id', 'created_at'],
            'sort'   => [
                'created_at' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        //return $search;
        //return $this->model->parseWheres($search)->paginate(5);
        if($input['model_id']){
            $model_id = $input['model_id'];
        }else{
            $model_id=0;
        }
        return $this->model->parseWheres($search)->where(['model_id'=>$model_id])->paginate(5);

    }


}